package lanou3g.myfirstapp36kr.activity;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import lanou3g.myfirstapp36kr.R;
import lanou3g.myfirstapp36kr.base.BaseActivity;

/**
 * Created by dllo on 16/8/11.
 */
public class TurnPicDetailsActivity extends BaseActivity {
    private WebView webView;
    private ImageView imageViewBack;
    private ImageView imageViewPop;
    private TextView textViewPopturnpicdetailsCancel;
    private FrameLayout frameLayout;
    @Override
    protected int getLayout() {
        return R.layout.activity_turn_pic_details;
    }

    @Override
    protected void initView() {
        webView = (WebView) findViewById(R.id.web_turn_pic_details);
        frameLayout = (FrameLayout) findViewById(R.id.pop_frame_layout);
        textViewPopturnpicdetailsCancel = (TextView)findViewById(R.id.tv_pop_turnpic_details_cancel);
        imageViewPop = (ImageView) findViewById(R.id.iv_pop);
        imageViewPop.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {

              frameLayout.setVisibility(View.VISIBLE);
            }
        });
        textViewPopturnpicdetailsCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(TurnPicDetailsActivity.this, "取消", Toast.LENGTH_SHORT).show();
                frameLayout.setVisibility(View.GONE);

            }
        });

        imageViewBack = (ImageView) findViewById(R.id.iv_turnpic_details_back);
        imageViewBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

//    private void showpop() {
//
//        popWindow.setWidth(900);
//        popWindow.setHeight(700);
//
//        popWindow.setContentView(popView);
//        popWindow.showAsDropDown(imageViewPop,0,1000);
//
//    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("urlNum");
        //if (BuildConfig.DEBUG) Log.d("====++++", url);
        WebViewClient webViewClient = new WebViewClient();
        webView.setWebViewClient(webViewClient);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setBuiltInZoomControls(true);
        openBrowser(url);

    }
    private void openBrowser(String url){
        webView.loadUrl(url);
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        getMenuInflater().inflate(R.menu.menu,menu);
//        return true;
//    }

//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        switch (item.getItemId()){
//
//        }
//        return super.onOptionsItemSelected(item);
//    }

    /**
     * 销毁activity之前remove子布局
     */

    @Override
    public void finish() {
        ViewGroup view = (ViewGroup) getWindow().getDecorView();
        view.removeAllViews();
        super.finish();

    }
}
